package com.study.${module}.controller.admin;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.study.server.domain.${Domain};
import com.study.server.dto.${Domain}Dto;
import com.study.server.dto.PageDto;
import com.study.server.dto.ResponseDto;
import com.study.server.exception.ValidatorException;
import com.study.server.service.${Domain}Service;
import com.study.server.util.ValidatorUtil;
import org.apache.ibatis.annotations.Param;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping(value = "/admin/${domain}")
public class ${Domain}Controller {

    @Resource
    private ${Domain}Service service;

    private static final Logger LOG = LoggerFactory.getLogger(ChapterController.class);
    public static final String BUSINESS_NAME = "${tableNameCn}";
    /**
     * 查询
     * @param pageDto
     * @return
     */

   @RequestMapping(value = "/list")
   public ResponseDto get(@RequestBody PageDto pageDto){
        ResponseDto objectResponseDto = new ResponseDto();
         System.out.println("pageDto {}"+pageDto);
        service.list(pageDto);
       objectResponseDto.setContent(pageDto);
     return objectResponseDto;
   }

    /**
     * 保存
     * @param ${domain}Dto
     * @return
     */
   @RequestMapping(value = "/save")
   public ResponseDto save(@RequestBody ${Domain}Dto ${domain}Dto){

     //       ValidatorUtil.require(${domain}Dto.getName(),"，课程");
      //      ValidatorUtil.require(${domain}Dto.getCourseId(),"，课程ID");
       //     ValidatorUtil.length(${domain}Dto.getCourseId(),"，课程ID",1,8);
        <#list fieldList as field>
        <#if field.name!="id" && field.nameHump!="createdAt" && field.nameHump!="updatedAt" && field.nameHump!="sort">
            <#if !field.nullAble>
        ValidatorUtil.require(${domain}Dto.get${field.nameBigHump}(), "${field.nameCn}");
            </#if>
            <#if (field.length > 0)>
        ValidatorUtil.length(${domain}Dto.get${field.nameBigHump}(), "${field.nameCn}", 1, ${field.length?c});
            </#if>
        </#if>
        </#list>

       ResponseDto objectResponseDto = new ResponseDto();
       System.out.println("${domain}Dto {}"+${domain}Dto);
      service.save(${domain}Dto);
       objectResponseDto.setContent(${domain}Dto);
     return objectResponseDto;

   }


    /**
     * 删除
     * @param
     * @return
     */
   @DeleteMapping(value = "/del/{id}")
   public ResponseDto del(@PathVariable String id){
       ResponseDto objectResponseDto = new ResponseDto();
       System.out.println("id {}"+id);
      service.del(id);

     return objectResponseDto;

   }
}
